Repository navigation
feat(nextjs): Send the render start of a cached page to the browser - #26397
Conversation
size-limit report 📦Compared: 4ae529e (PR test merge using develop at 7f77bb2) Against: 7f77bb2 (develop) · base run #66275 ✅ Baseline matches: this diff contains only this PR's changes.
|
A pageload of a cached page links to the render that produced the HTML, but the age of that HTML is unknown. Next.js now writes a `sentry-render-start` meta tag next to `sentry-cache-origin`, in whole UNIX seconds. The browser sets `page.server_rendering.age` on the pageload span. The tag holds the start of the linked render span. Without a recording span it holds the current time, because Next.js computes the meta tags at the start of the prerender.
312694e to
c5429d5
Compare
Optional E2E testsSome optional checks were not successful. They do not block the merge. 5 not successful, 58 successful. See the run.
Successful checks
|
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c5429d5. Configure here.
Auto-merge was disabled for another pull request in the stack
|
|
||
| // A pageload starts at the time origin. The server and the browser clocks differ, so a render shortly before the | ||
| // pageload can seem to start after it. | ||
| function getRenderAge(renderStart: string | null | undefined): number | undefined { |
There was a problem hiding this comment.
This only clamps the lower bound, a sentry-render-start of 0 gives page.server_rendering.age: 1794834076. Should we generally drop attributes that seem implausible? Maybe cap it at a year or whatever?
There was a problem hiding this comment.
It's very unlikely that this happens (I hope the server clocks are quite correct :D). But it's fair to cap it. 1 year seems fine.
A `sentry-render-start` of 0 gave an age of about 57 years. The SDK writes the value from the server clock, so only a clock that jumped back, for example to 1970, gives such an age. Sites deploy again within a year, so the browser sets no `page.server_rendering.age` above one year.
Pull Request is not mergeable
…mponents-ticket-20 # Conflicts: # dev-packages/e2e-tests/test-applications/nextjs-16-cacheComponents/tests/cacheOrigin-pageloadConnection.spec.ts # dev-packages/e2e-tests/test-applications/nextjs-16-streaming-cacheComponents/tests/cacheOrigin-pageloadConnection.spec.ts # packages/core/src/index.ts
#26398) Stacked on #26397. ## What SvelteKit now writes the `sentry-render-start` meta tag next to `sentry-cache-origin` on prerendered and Vercel ISR pages. The browser sets `page.server_rendering.age` from it, as in #26397. ## Why The tag holds the start of the linked render span. Without a recording span (build prerender, unsampled request), it holds the request start that `sentryHandle` records. The current time would be too late by the whole render, because Kit calls `transformPageChunk` only after the render. `_INTERNAL_getCacheOriginMetaTags` is the new shared writer for both tags. The old `_INTERNAL_getCacheOriginMetaTag` stays until Nuxt moves to the new one in the next PR.
…6399) Stacked on #26398. ## What Nuxt now writes the `sentry-render-start` meta tag next to `sentry-cache-origin` on cached and prerendered pages. The browser sets `page.server_rendering.age` from it, as in #26397. ## Why The tag holds the start of the linked render span. Without a recording span, it holds the request start. Nitro calls `render:html` only after the whole render, so a Nitro `request` hook records the start on `event.context`. The hook also fires for prerender requests, and a background SWR revalidation sees the context of the request that started it. On Cloudflare, this also gives the right start when the async context is lost.
What
Next.js now writes a
sentry-render-startmeta tag (whole UNIX seconds) next tosentry-cache-origin. The browser uses it to setpage.server_rendering.ageon the pageload span, so the UI can show how old the cached HTML was. The browser side is in@sentry/core, so SvelteKit and Nuxt only need to write the tag. They follow in stacked PRs.Why
The
cache_originlink tells you which render produced a cached page, but not how old that page is. That linked span is often not sampled or already gone, so the browser needs the start time itself.The tag holds the start of the linked render span. Without a recording span, it holds the current time, which is the render start, because Next.js computes the meta tags at the start of
prerenderToStream. The attribute comes from getsentry/sentry-conventions#799, which is not merged yet, so the name is a local constant with a TODO.A
Server-Timingheader (#26107) does not replace the tag: shared-cacheable responses and Vercel do not send it, and it cannot hold the render time of a cached shell.